
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;


/**
 * wnos.dim_date 插入语句
 * @author Ficle
 *
 */
public class InsertTest {

	
	public static void main(String[] args) throws ParseException {
		
//		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        //跨年不会出现问题
        //如果时间为：2016-03-18 11:59:59 和 2016-03-19 00:00:01的话差值为 0
//        Date fDate=sdf.parse("2019-01-01");
//        Date oDate=sdf.parse("2020-01-01");
//        long days=(oDate.getTime()-fDate.getTime())/(1000*3600*24);
        //System.out.print(days);
        
        
        List<String> list = new ArrayList<String>(400);
		for(int i = 2; i <= 12; i++) {
			list.addAll(getMonthFullDay(2019, i));
		}
		
		List<String> list2 = new ArrayList<String>(400);
		for(int i = 2; i <= 12; i++) {
			list2.addAll(getMonthFullDay2(2019, i));
		}
		
		List<String> list3 = new ArrayList<String>(400);
		for(int i = 2; i <= 12; i++) {
			list3.addAll(getMonthFullDay3(2019, i));
		}
		
		List<String> years = new ArrayList<String>(400);
		List<String> months = new ArrayList<String>(400);
		List<String> dayss = new ArrayList<String>(400);
		for (int i = 0; i < list.size(); i++) {
			String str = list.get(i);
			str = str.replaceAll("-", "");
			String year = str.substring(0, 4);
			years.add(year);
			String month = str.substring(4, 6);
			months.add(month);
			String day = str.substring(6, 8);
			dayss.add(day);
		}

		List<String> list5 = new ArrayList<String>(400);
		for(int i = 0; i < years.size(); i++) {
			list5.add(getDayOfWeek(Integer.parseInt(years.get(i)), 
					Integer.parseInt(months.get(i)), Integer.parseInt(dayss.get(i))));
		}
		
		List<String> list6 = new ArrayList<String>(400);
		for(int i = 0; i < list5.size(); i++) {
			list6.add(getWeekDayorWorkDay(list5.get(i)));
		}
		
		
		int j = 3684;
		for (int i = 0; i < list.size(); i++) {
			StringBuffer sb = new StringBuffer();
			sb.append(" insert into wnos.dim_date (ID,DAY,DAY_DESCR,DAY_END_TIME,WEEK_DAY,EXT_ATTR1,UPDATE_TIME) ");
			sb.append(" values ( ");
			sb.append(j++);
			sb.append(",");
			sb.append("'" + list.get(i) + "'");
			sb.append(",");
			sb.append("'" + list2.get(i) + "'");
			sb.append(",");
			sb.append("to_date('" + list3.get(i) + "','yyyy/mm/dd')");
			sb.append(",");
			sb.append("'" + list5.get(i) + "'");
			sb.append(",");
			sb.append("'" + list6.get(i) + "'");
			sb.append(",");
			sb.append("to_date('2019/01/03 16:30:24','yyyy/mm/dd hh24:mi:ss')");
			sb.append(" ); ");
			String sql = sb.toString();
			System.out.println(sql);
		}
		
		
		
		/*for (int i = 0; i < list6.size(); i++) {
			System.out.println(list6.get(i));
		}*/
		
	}
	
	
	public static List<String> getMonthFullDay(int year , int month){
	    SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");
	    List<String> fullDayList = new ArrayList<>(32);
	    // 获得当前日期对象
	    Calendar cal = Calendar.getInstance();
	    cal.clear();// 清除信息
	    cal.set(Calendar.YEAR, year);
	    // 1月从0开始
	    cal.set(Calendar.MONTH, month-1 );
	    // 当月1号
	    cal.set(Calendar.DAY_OF_MONTH,1);
	    int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	    for (int j = 1; j <= count ; j++) {
	        fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime()));
	        cal.add(Calendar.DAY_OF_MONTH,1);
	    }
	    return fullDayList;
	}
	
	public static List<String> getMonthFullDay2(int year , int month){
	    SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("yyyy年MM月dd");
	    List<String> fullDayList = new ArrayList<>(32);
	    // 获得当前日期对象
	    Calendar cal = Calendar.getInstance();
	    cal.clear();// 清除信息
	    cal.set(Calendar.YEAR, year);
	    // 1月从0开始
	    cal.set(Calendar.MONTH, month-1 );
	    // 当月1号
	    cal.set(Calendar.DAY_OF_MONTH,1);
	    int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	    for (int j = 1; j <= count ; j++) {
	        fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime()));
	        cal.add(Calendar.DAY_OF_MONTH,1);
	    }
	    return fullDayList;
	}
	
	public static List<String> getMonthFullDay3(int year , int month){
	    SimpleDateFormat dateFormatYYYYMMDD = new SimpleDateFormat("yyyy/MM/dd");
	    List<String> fullDayList = new ArrayList<>(32);
	    // 获得当前日期对象
	    Calendar cal = Calendar.getInstance();
	    cal.clear();// 清除信息
	    cal.set(Calendar.YEAR, year);
	    // 1月从0开始
	    cal.set(Calendar.MONTH, month-1 );
	    // 当月1号
	    cal.set(Calendar.DAY_OF_MONTH,1);
	    int count = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
	    for (int j = 1; j <= count ; j++) {
	        fullDayList.add(dateFormatYYYYMMDD.format(cal.getTime()));
	        cal.add(Calendar.DAY_OF_MONTH,1);
	    }
	    return fullDayList;
	}
	
	/**
	 * 获取某年某月某日 是 星期几
	 * @param year
	 * @param month
	 * @param day
	 * @return
	 */
	public static String getDayOfWeek(int year , int month , int day){
	    //本地化
	    Locale.setDefault(Locale.CHINA);
	    String[] dayStringOfWeek = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
	    Calendar cal = Calendar.getInstance();
	    cal.set(Calendar.YEAR, year);
	    cal.set(Calendar.MONTH, month - 1);
	    cal.set(Calendar.DAY_OF_MONTH, day);
	    // Java中Calendar.DAY_OF_WEEK其实表示：一周中的第几天，所以他会受到第一天是 星期一 还是 星期日 的影响
	    int d = cal.get(Calendar.DAY_OF_WEEK);
	    return dayStringOfWeek[d-1];
	}
	
	public static String getWeekDayorWorkDay(String str){
		if(str != null) {
			if(str.equals("星期一") || str.equals("星期二") || str.equals("星期三") || str.equals("星期四") || str.equals("星期五")) {
				return "工作日";
			}else {
				return str;
			}
		}
		return null;
	}
	
}
